package com.github.alenfive;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

public class ServletUtils {
    private static final Logger logger = LoggerFactory.getLogger(ServletUtils.class);

    public static Map<String, String> queryAllUrlParams(HttpServletRequest request) {
        Map<String, String> map = new TreeMap();
        Enumeration<String> params = request.getParameterNames();
        while (params.hasMoreElements()) {
            String paramName = params.nextElement();
            map.put(paramName, request.getParameter(paramName));
        }
        return map;
    }

    public static Map<String, String> queryAllHeaders(HttpServletRequest request) {
        Map<String, String> map = new TreeMap();
        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()) {
            String headerName = headers.nextElement();
            map.put(headerName, request.getHeader(headerName));
        }
        return map;
    }

}
